name: Parse Markdown and Generate JSON

on:
  schedule:
    - cron: '0 0 * * *' # 00:00 UTC
  workflow_dispatch:

jobs:
  parse_markdown:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: 3.10.11

      - name: Install Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install bs4 markdown2 prettytable PyGithub flake8 black
        continue-on-error: true

      - name: Run Flake8 (Linting)
        run: flake8 code/

      - name: Check code formatting
        run: black --check code/

      - name: Run Markdown Parser
        id: parse
        run: python code/markdown_to_json_parser.py
        working-directory: ${{ github.workspace }}
        continue-on-error: true
        env:
          PAPER_TOKEN: ${{ secrets.PAPER_TOKEN }}

      - name: Upload JSON files
        uses: actions/upload-artifact@v4
        with:
          name: json_data
          path: ${{ github.workspace }}/json_data

      - name: Set output status
        run: echo "status=${{ steps.parse.outcome }}" >> $GITHUB_ENV
